<template>
	<view class="wrap">
		<u-navbar :title="$t('index.sycs')" title-width="340" :border-bottom="false" back-icon-color="#fff" title-color="#fff" :background="{ backgroundColor: '#0030A8' }"></u-navbar>
		<view class="tom-container">
			<view class="cell">
				<view class="cell_tab">
					<view class="cell-suo">
						<!-- <view class="cell-label">交易所</view> -->
						<view @tap="showSelectChange = true" class="cell-main">
							<text v-if="exchangeList[exchange]" class="cell-main-input" :class="{ 'cell-main-input-place': !exchangeList[exchange]['label'] }">{{ exchangeList[exchange]['label'] }}</text>
							<text class="cell-main-input cell-main-input-place" v-else>{{$t("qxzjys")}}</text>
							<u-icon name="you" custom-prefix="custom-icon" size="28"></u-icon>
						</view>
						<view class="explain">{{$t("cssjbdbzzylsj")}}</view>
					</view>
					<view class="right">
						<view class="item" :class="cell_tab_index == 'STEADY' ? 'action' : ''" @tap="cell_tab('STEADY')">{{$t("bsx")}}</view>
						<view class="item" :class="cell_tab_index == 'RADICAL' ? 'action' : ''" @tap="cell_tab('RADICAL')">{{$t("jjx")}}</view>
					</view>
				</view>
				<view class="cell_tab_tiem">
					<view :class="cell_tab_tiem_index == '1week' ? 'action' : ''" @tap="cell_tab_tiem('1week')">{{$t("yz")}}</view>
					<view :class="cell_tab_tiem_index == '1month' ? 'action' : ''" @tap="cell_tab_tiem('1month')">{{$t("yy")}}</view>
					<view :class="cell_tab_tiem_index == '3month' ? 'action' : ''" @tap="cell_tab_tiem('3month')">{{$t("sy")}}</view>
					<view :class="cell_tab_tiem_index == '6month' ? 'action' : ''" @tap="cell_tab_tiem('6month')">{{$t("bn")}}</view>
					<view :class="cell_tab_tiem_index == '1year' ? 'action' : ''" @tap="cell_tab_tiem('1year')">{{$t("yn")}}</view>
				</view>
			</view>
			<u-select :cancelText="$t('quxiao')" :confirmText="$t('queren')" v-model="showSelectChange" :default-value="[exchange || 0]" mode="single-column" :list="exchangeList" @confirm="confirmChangeSelect"></u-select>
			<view class="api_block">
				<mescroll-uni :fixed="false" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
					<view class="list" v-for="(item, index) in list" :key="index" @tap="toOpen(index)" :class="list_open_index == index ? 'list_active' : ''">
						<view class="list_top">
							<view class="left">
								<view class="left_title">
									<view class="text">{{$t("bz")}}</view>
									<view class="text">{{$t("ykl")}}</view>
									<view class="text">{{$t("zdhc")}}</view>
								</view>
								<view class="left_list">
									<view class="item">
										<image class="img" :src="`/static/bizhong/${item.exchangeCoin}.png`"></image>
										{{ item.exchangeCoin }}
									</view>
									<view class="item" :class="item.profitTotalRatioFlag == 1 ? 'green' : 'red'">{{ item.profitTotalRatio }}</view>
									<view class="item lan" :class="item.riskMaxRatio * 100 >= 50 ? 'red' : ''">{{ $BigNumber(item.riskMaxRatio).multipliedBy(100) }}%</view>
								</view>
							</view>
							<view class="right"><u-icon class="icon_you" name="you" custom-prefix="custom-icon" size="20"></u-icon></view>
						</view>
						<view class="list_cell">
							<view class="item">
								<view class="list_cell_title">{{$t("sdcs")}}</view>
								<view class="list_cell_text">
									<!-- {{item.firstOrderCost}} -->
									{{ item.grandOrderStat_list[0] || 0 }}
								</view>
							</view>
							<view class="item">
								<view class="list_cell_title">{{$t("bcyc")}}</view>
								<view class="list_cell_text">{{ item.grandOrderStat_list[1] || 0 }}</view>
							</view>
							<view class="item">
								<view class="list_cell_title">{{$t("bcec")}}</view>
								<view class="list_cell_text">{{ item.grandOrderStat_list[2] || 0 }}</view>
							</view>
							<view class="item">
								<view class="list_cell_title">{{$t("bcsc")}}</view>
								<view class="list_cell_text">{{ item.grandOrderStat_list[3] || 0 }}</view>
							</view>
							<view class="item">
								<view class="list_cell_title">{{$t("bcsic")}}</view>
								<view class="list_cell_text">{{ item.grandOrderStat_list[4] || 0 }}</view>
							</view>
							<view class="item">
								<view class="list_cell_title">{{$t("bcwc")}}</view>
								<view class="list_cell_text">{{ item.grandOrderStat_list[5] || 0 }}</view>
							</view>
							<view class="item">
								<view class="list_cell_title">{{$t("bclc")}}</view>
								<view class="list_cell_text">{{ item.grandOrderStat_list[6] || 0 }}</view>
							</view>
							<view class="item">
								<view class="list_cell_title">{{$t("bcqc")}}</view>
								<view class="list_cell_text">{{ item.grandOrderStat_list[7] || 0 }}</view>
							</view>
						</view>
					</view>
				</mescroll-uni>
			</view>
		</view>
	</view>
</template>

<script>
import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins.js';
import { mapState, mapGetters } from 'vuex';
export default {
	mixins: [MescrollMixin],
	data() {
		return {
			list: [],
			cell_tab_index: 'STEADY',
			cell_tab_tiem_index: '1week',
			list_open_index: null,
			// 是否显示交易所列表
			showSelectChange: false,
			// 交易所列表
			exchangeList: [],
			// 选中交易所
			exchange: '',
			exchangeName:'',
			key_value:{},
		};
	},
	onLoad(){
		this.$api.userApi
			.getExchanges({
				qryCode:'calReward'
			})
			.then(res => {
				let arr = res.data.exchangeList || [];
				let exchangeList = [];
				arr.forEach((item, index) => {
					exchangeList.push({ label: item.exchangeNameShow, value: index });
					this.key_value[item.exchangeNameShow] = item.exchangeName;
					if(this.exchangeName == item.exchangeName) this.exchange = index;
				});
				this.exchangeList = exchangeList;
			}).catch(res =>{
				
			})
	},
	methods: {
		// 选择交易所
		confirmChangeSelect(e) {
			this.exchange = e[0]['value'];
			this.exchangeName = this.key_value[e[0]['label']];
			this.mescroll.resetUpScroll();
		},
		cell_tab(index) {
			/*类型切换*/
			this.cell_tab_index = index;
			this.list = [];
			this.mescroll.resetUpScroll();
		},
		cell_tab_tiem(index) {
			/*时间切换*/
			this.list = [];
			this.cell_tab_tiem_index = index;
			this.mescroll.resetUpScroll();
		},
		// 下拉刷新
		downCallback() {
			this.mescroll.resetUpScroll();
		},
		// 上拉加载
		upCallback(page) {
			uni.showLoading({
				mask: true,
				title: this.$t("loading.title")
			});
			this.$api.consoleApi
				.getIncomePredictIndex({
					cycleType: this.cell_tab_tiem_index,
					dangerType: this.cell_tab_index,
					exchangeName:this.exchangeName,
					page: page.num
				})
				.then(res => {
					var a = res.data || [];
					a.forEach(function(item) {
						var _a = item.grandOrderStat.split('|');
						item.grandOrderStat_list = _a;
					});
					let list = a;
					this.mescroll.endSuccess(list.length);
					if (page.num == 1) this.list = []; //如果是第一页需手动制空列表
					this.list = this.list.concat(list); //追加新数据
					console.log(this.list);
					uni.hideLoading();
				})
				.catch(res => {
					uni.hideLoading();
				});
		},
		toOpen(index) {
			if (this.list_open_index != index) {
				this.list_open_index = index;
			} else {
				this.list_open_index = null;
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.tom-container {
	.explain{
		font-size:26rpx;
		color:#666666;
		margin-top:20rpx;
	}
	.cell-suo{
		font-size:28rpx;
		.cell-label{
			color:#0030A8;
		}
		.cell-main{
			color:#0030A8;
		}
	}
	.cell {
		padding: 40rpx 30rpx 30rpx 30rpx;
		.cell_tab {
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 24rpx;
			color: #666666;
			.right {
				display: flex;
				align-items: center;
				justify-content: space-between;
				background-color: #fff;
				border-radius: 100rpx;
				width: 300rpx;
				text-align: center;
				color: #333;
				overflow: hidden;
				box-sizing: border-box;
				// border: 1px solid #cccccc;
				box-shadow: 0rpx 0rpx 2px #ccc;
				.item {
					height: 74rpx;
					line-height: 72rpx;
					width: 100%;
					font-size: 30rpx;
					font-weight: bold;
				}
				.action {
					background-color: $text-color;
					color: #fff;
				}
			}
		}
		.cell_tab_tiem {
			display: flex;
			justify-content: space-around;
			align-items: center;
			font-size: 36rpx;
			color: #666666;
			margin-top: 30rpx;
			.action {
				color: $text-color;
				font-weight: bold;
				position: relative;
			}
			.action::before {
				content: '';
				position: absolute;
				width: 100%;
				height: 6rpx;
				background-color: $text-color;
				bottom: -16rpx;
				border-radius: 12rpx;
				overflow: hidden;
			}
		}
	}
	.api_block {
		flex: 1;
		display: flex;
		flex-direction: column;
		margin: $nr-padd;
		overflow: auto;
		.list {
			height: 154rpx;
			overflow: hidden;
			background-color: #fff;
			border-radius: 20rpx;
			margin-bottom: 10rpx;
			padding: 20rpx 0rpx;
			.list_top {
				display: flex;
				justify-content: space-between;
				padding: 0rpx 28rpx;
				.left {
					width: 100%;
					padding-bottom: 14rpx;
					.left_title {
						display: flex;
						justify-content: space-between;
						.text {
							width: 100%;
							font-size: 32rpx;
							color: #333;
							font-weight: bold;
						}
						.text:nth-child(1) {
							padding-left: 26rpx;
							box-sizing: border-box;
						}
						.text:nth-child(2) {
							text-align: center;
						}
						.text:nth-child(3) {
							text-align: center;
						}
					}
					.left_list {
						margin-top: 30rpx;
						display: flex;
						justify-content: space-between;
						.item {
							color: #333;
							font-size: 26rpx;
							font-weight: bold;
							display: flex;
							align-items: center;
							width: 100%;
							.img {
								width: 40rpx;
								height: 40rpx;
								border-radius: 40rpx;
								margin-right: 20rpx;
							}
						}
						.item:nth-child(2) {
							justify-content: center;
						}
						.item:nth-child(3) {
							justify-content: center;
						}
						.lan {
							color: $text-color;
						}
						.red {
							color: $tom-text-red;
						}
						.green {
							color: $tom-text-green;
						}
					}
				}
				.right {
					padding-left: 30rpx;
					.icon_you {
						transform: rotate(90deg);
					}
				}
			}
			.list_cell {
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;
				padding: 10rpx 28rpx 10rpx 28rpx;
				border-top: solid 6rpx #f2f2f2;
				margin-top: 10rpx;
				.item {
					padding-top: 20rpx;
					width: 25%;
					text-align: center;
					.list_cell_title {
						font-size: 28rpx;
						color: #666;
						margin-bottom: 14rpx;
					}
					.list_cell_text {
						font-size: 26rpx;
						color: $text-color;
					}
				}
				// .item:nth-child(4n+1){
				// 	text-align: left;
				// }
				// .item:nth-child(4n+4){
				// 	text-align: right;
				// }
			}
		}
		.list_active {
			height: auto;
			.list_top {
				.right .icon_you {
					transform: rotate(-90deg);
				}
			}
		}
	}
}
</style>
